package com.tsvetanv.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.tsvetanv.model.CategoryMessage;
import com.tsvetanv.model.Message;

public class NewsServiceImpl implements NewsService {
	private static final Logger logger = Logger
			.getLogger(NewsServiceImpl.class);
	private static Message msg1;
	private static Message msg2;
	private static Message msg3;
	private static Message msg4;
	static {
		try {
			msg1 = new Message("New patch 2.1", new SimpleDateFormat(
					"dd.MM.yyyy").parse("15.10.2010"), CategoryMessage.INTERNAL);
			msg2 = new Message("Revised product brand", new SimpleDateFormat(
					"dd.MM.yyyy").parse("21.04.2010"), CategoryMessage.EXTERNAL);
			msg3 = new Message("Company moves in new office",
					new SimpleDateFormat("dd.MM.yyyy").parse("20.07.2011"),
					CategoryMessage.EXTERNAL);
			msg4 = new Message("Director fired", new SimpleDateFormat(
					"dd.MM.yyyy").parse("21.09.2011"), CategoryMessage.INTERNAL);
		} catch (ParseException e) {
			logger.error("Parsing exception of message.");
		}
	}

	@Override
	public List<Message> getNews() {
		List<Message> messages = new ArrayList<Message>();
		messages.add(msg1);
		messages.add(msg2);
		messages.add(msg3);
		messages.add(msg4);
		logger.info("Extracting messages finished successfully.");
		return messages;
	}

}
